﻿<!DOCTYPE HTML>
<html>
	<head>
		<title>chapter5</title>
	</head>
	<body>
		<script type="text/javascript">
			//test object
			/*
			var object = new Object();
			object.name = 'leima';
			object.age = 25;
			alert(object);
			alert(object.name);
			alert(object.age);
			
			object = {name:'tom',age:29};
			alert(object);
			alert(object.name);
			alert(object.age);
			
			object = {};
			object.name='jerrey';
			object.age=29;
			alert(object.name);
			alert(object.age);
			
			function displayInfo(arg0){
				if(typeof(arg0.name) == "string" ){
					alert(arg0.name);
				}
				if(typeof(arg0.age) == "number" ){
					alert(arg0.age);
				}
			}
			
			displayInfo({name:'tom',age:29});
			displayInfo({name:'tom'});
			*/
			//test array
			/*
			//create type1
			
			var a = new Array('name','age');
			for(i in a){
				alert(a[i]);
			}
			
			//create type2
			var b = ['name','age','gender'];
			//var b = ['name','age'];
			for(i in b){
				alert(b[i]);
			}
			*/
			//test length
			/*
			var color = ['black','green','red'];
			
			color.length = 2;
			color[99] = 'yellow';
			alert(color.length);
			alert(color[99]);
			
			alert(color.toString());
			alert(color.valueOf());
			alert(color);
			*/
			//test toLocaleString
			/*
			var person1= {
				toLocaleString:function(){
					return 'leima';
				},
				toString:function(){
					return 'malei';
				}
			};
			var person2= {
				toLocaleString:function(){
					return 'tomson';
				},
				toString:function(){
					return 'tom';
				}
			};
			var a = new Array(person1,person2);
			alert(a);
			alert(a.join('||'));
			alert(a.toString());
			alert(a.toLocaleString());
			*/
			
			//test stack
			/*
			var color = ['white'];
			color.push('black','blue');
			alert(color);
			alert(color.length);
			color.pop();
			alert(color);
			alert(color.length);
			*/
			
			//test queue
			/*
			var color = ['white'];
			color.push('black','blue');
			//color:white,black,blue
			alert(color);
			alert(color.length);
			var item = color.shift();
			//item:white
			alert(item);
			alert(color);
			alert(color.length);
			var color = ['white'];
			var count = color.unshift('black','blue');
			//color:black,blue,white
			alert(color);
			alert(count);
			var item = color.pop();
			//item:white
			alert(item);
			alert(color);
			alert(color.length);
			*/
			
			//test RegExp
			/*
			var pattern1 = /\[bc\]at/i;
			alert(pattern1.global);
			alert(pattern1.ignoreCase);
			alert(pattern1.lastIndex);
			alert(pattern1.multiline);
			alert(pattern1.source);
			
			var pattern2 = new RegExp(/\[bc\]at/);
			alert(pattern2.global);
			alert(pattern2.ignoreCase);
			alert(pattern2.lastIndex);
			alert(pattern2.multiline);
			alert(pattern2.source);
			
			var text = 'mom and dad and baby';
			var pattern = /mom( and dad( and baby)?)?/gi;
			var matches = pattern.exec(text);
			alert(matches.index);
			alert(matches.input);
			alert(matches[0]);
			alert(matches[1]);
			alert(matches[2]);
			
			var text = 'cat,bat,fat,sat';
			var pattern1 = /.at/;
			var matches = pattern1.exec(text);
			alert(matches.index);
			alert(matches[0]);
			alert(pattern1.lastIndex);
			matches = pattern1.exec(text);
			alert(matches.index);
			alert(matches[0]);
			alert(pattern1.lastIndex);
			*/
			var text = 'cat, bat, fat, sat';
			var pattern2 = /.at/g;
			var matches = pattern2.exec(text);
			alert(matches.index);
			alert(matches[0]);
			alert(pattern2.lastIndex);
			matches = pattern2.exec(text);
			alert(matches.index);
			alert(matches[0]);
			alert(pattern2.lastIndex);
			
			
		</script>
	</body>	
</html>